package com.onlyxiahui.common.action.description.box;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.onlyxiahui.common.action.description.box.data.ValidationData;
import com.onlyxiahui.common.action.description.enums.type.ValidatorType;

/**
 * Description <br>
 * Date 2020-01-09 09:11:09<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class ValidationDataBox {

	Map<String, List<ValidationData>> map = new HashMap<>();

	public ValidationDataBox() {
		initialize();
	}

	public void initialize() {
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.AssertFalse", "boolean", "", "false", "groups",
				"javax.validation.constraints.AssertFalse$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.AssertTrue", "boolean", "", "true", "groups",
				"javax.validation.constraints.AssertTrue$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.DecimalMax", "max", "value", "", "groups",
				"javax.validation.constraints.DecimalMax$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.DecimalMin", "min", "value", "", "groups",
				"javax.validation.constraints.DecimalMin$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Digits", "numberIntegerDigits", "integer", "", "groups",
				"javax.validation.constraints.Digits$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Digits", "numberFractionDigits", "fraction", "", "groups",
				"javax.validation.constraints.Digits$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Email", "email", "regexp", "", "groups",
				"javax.validation.constraints.Email$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Future", "future", "", "true", "groups",
				"javax.validation.constraints.Future$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.FutureOrPresent", "futureOrPresent", "", "true", "groups",
				"javax.validation.constraints.FutureOrPresent$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Max", "max", "value", "", "groups",
				"javax.validation.constraints.Max$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Min", "min", "value", "", "groups",
				"javax.validation.constraints.Min$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Negative", "<", "", "0", "groups",
				"javax.validation.constraints.Negative$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.NegativeOrZero", "<=", "", "0", "groups",
				"javax.validation.constraints.NegativeOrZero$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.NotBlank", "notBlank", "", "true", "groups",
				"javax.validation.constraints.NotBlank$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.NotEmpty", "notEmpty", "", "true", "groups",
				"javax.validation.constraints.NotEmpty$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.NotNull", "notNull", "", "true", "groups",
				"javax.validation.constraints.NotNull$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Null", "null", "", "true", "groups",
				"javax.validation.constraints.Null$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Past", "past", "", "true", "groups",
				"javax.validation.constraints.Past$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.PastOrPresent", "pastOrPresent", "", "true", "groups",
				"javax.validation.constraints.PastOrPresent$List", "value");

		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Pattern", "pattern", "regexp", "", "groups",
				"javax.validation.constraints.Pattern$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Positive", ">", "", "0", "groups",
				"javax.validation.constraints.Positive$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.PositiveOrZero", ">=", "", "0", "groups",
				"javax.validation.constraints.PositiveOrZero$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Size", "minSize", "min", "", "groups",
				"javax.validation.constraints.Size$List", "value");
		this.put(ValidatorType.Validation.getName(), "javax.validation.constraints.Size", "maxSize", "max", "", "groups",
				"javax.validation.constraints.Size$List", "value");

		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.Email", "email", "regexp", "", "groups",
				"org.hibernate.validator.constraints.Email$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.Length", "minLength", "min", "", "groups",
				"org.hibernate.validator.constraints.Length$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.Length", "maxLength", "max", "", "groups",
				"org.hibernate.validator.constraints.Length$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.NotBlank", "notBlank", "", "true", "groups",
				"org.hibernate.validator.constraints.NotBlank$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.NotEmpty", "notEmpty", "", "true", "groups",
				"org.hibernate.validator.constraints.NotEmpty$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.Range", "min", "min", "", "groups",
				"org.hibernate.validator.constraints.Range$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.Range", "max", "max", "", "groups",
				"org.hibernate.validator.constraints.Range$List", "value");
		this.put(ValidatorType.Validation.getName(), "org.hibernate.validator.constraints.URL", "url", "", "true", "groups",
				"org.hibernate.validator.constraints.URL$List", "value");
	}

	public void put(
			String validatorName,
			String annotation,
			String validType,
			String validPropertyName,
			String validDefaultValue,
			String groupPropertyName,
			String repeatableAnnotation,
			String repeatablePropertyName) {
		put(new ValidationData(validatorName, annotation, validType, validPropertyName, validDefaultValue, groupPropertyName, repeatableAnnotation, repeatablePropertyName));
	}

	public void put(ValidationData data) {
		if (null != data) {
			String key = data.getAnnotation();
			if (null != key && !key.isEmpty()) {
				List<ValidationData> list = map.get(key);
				if (null == list) {
					list = new ArrayList<>();
					map.put(key, list);
				}

				list.add(data);
			}
		}
	}

	public List<ValidationData> get(String key) {
		return map.get(key);
	}

	public List<ValidationData> allList() {
		List<ValidationData> list = new ArrayList<>();
		for (List<ValidationData> vs : map.values()) {
			list.addAll(vs);
		}
		return list;
	}
}
